{extend name="common/base"}
{block name="content"}
<style>
    #add-user {
        color: #000!important;
    }
    #add-user .am-u-md-12,#add-user .am-form-field {
        margin-bottom: 10px;
        color: #000!important;
    }
</style>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">代理列表</div>


                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <button class="am-btn-success am-btn" data-am-modal="{target: '#add-user', closeViaDimmer: 0, width: 400}">添加代理</button>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-6">
                        <form action="{:url('index')}">
                            <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                <input type="text" class="am-form-field " name="search" placeholder="输入登录名/昵称搜索...">
                                <span class="am-input-group-btn">
                                <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="submit"></button>
                             </span>
                            </div>
                        </form>
                    </div>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                            <tr>
                                <th>代理id</th>
                                <th>代理登录名</th>
                                <th>代理昵称</th>
                            </tr>
                            </thead>
                            <tbody id="ajax-wrapper">

                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr ajax-page">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="footer-js"}
<div class="am-modal am-modal-no-btn" tabindex="-1" id="add-user">
    <div class="am-modal-dialog">
        <div class="am-modal-hd"> 添加代理
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <form action="" class="my-form">
        <div class="am-modal-bd">
            <div class="am-u-md-12">
                <input type="text" name="username" class="am-form-field" placeholder="代理登录名称">
            </div>
            <div class="am-u-md-12">
            <input type="password" name="password" class="am-form-field" placeholder="代理密码">
            </div>
            <div class="am-u-md-12">
            <input type="text" name="nickname" class="am-form-field" placeholder="代理昵称">
            </div>
            <div class="am-u-md-12">
            <input type="number" name="id2" class="am-form-field" placeholder="代理id">
            </div>
        </form>
            <div class="am-u-md-12">
            <button class="am-btn-success am-btn" id="submit" type="button">提交</button>
            </div>
        </div>
    </div>
</div>
<script src="__ADMIN__/template.js"></script>
<script id="ajax-content" type="text/html">
    <%for(var i = 0 ; i<data.length; i++) {%>
    <tr>
        <td><%=data[i].id2%></td>
        <td><%=data[i].username%></td>
        <td><%=data[i].nickname%></td>
    </tr>
    <%}%>
</script>
<script>
    var config = {
        success : function (res) {
            console.log(res)
            var html = template($('#ajax-content').html() , {data:res.ad_list.data})

            $('#ajax-wrapper').html(html)
            $('.ajax-page').html(res.page)
        }
    };
    $.ajax(config);
    $('.ajax-page').on('click' , 'a' , function (e) {
        e.preventDefault();
        var url = $(this).attr('href');
        config.url = url;
        $.ajax(config);
    })

    $('#submit').click(function () {
        var fd = new FormData($('.my-form')[0]);
        $.ajax({
            type : 'post' ,
            url : '{:url("addUser")}',
            data :fd,
            // 告诉jQuery不要去处理发送的数据
            processData : false,
            // 告诉jQuery不要去设置Content-Type请求头
            contentType : false,
            success : function (res) {
                $('#add-user').modal('close')
            }
        });
    });
</script>
{/block}